package com.example.eshop_ssm.service.impl;


import com.example.eshop_ssm.entity.TbBookInfo;
import com.example.eshop_ssm.entity.TbTypeInfo;
import com.example.eshop_ssm.mapper.AddBookMapper;
import com.example.eshop_ssm.service.AddBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AddBookServiceImpl implements AddBookService {
    @Autowired
    private AddBookMapper addBookMapper ;
    @Override
    public List<TbTypeInfo> selectType() {
        return addBookMapper.selectType();
    }

    @Override
    public List<TbTypeInfo> selectTypeTwo(String type_id) {
        return addBookMapper.selectTypeTwo(Integer.parseInt(type_id));
    }

    @Override
    public TbBookInfo selectUpdateBook(String book_id) {
        TbBookInfo tbBook = addBookMapper.selectUpdateBook(Integer.parseInt(book_id));
        return tbBook;
    }

    @Override
    public Map<String, Object> addBook(TbBookInfo tbBook){

        Integer integer = addBookMapper.addBook(tbBook);
        HashMap<String, Object> resultMap = new HashMap<>();
        resultMap.put("effectRow",integer);
        resultMap.put("book_id",tbBook.getBookId());

        return resultMap;

    }

    @Override
    public Integer addBookPic(String book_id, String picArray) {
        String[] picnameArray = picArray.split(",");
        HashMap<Object, Object> picMap = new HashMap<>();
        picMap.put("book_id",book_id);
        picMap.put("picnameArray",picnameArray);

        return addBookMapper.addBookPic(picMap);
    }


}
